package p.ithorns.integration.dynamic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import p.ithorns.integration.dynamic.config.EnableDynamicModuleAutoConfiguration;
import p.ithorns.integration.dynamic.module.ModuleService;

import java.io.FileNotFoundException;

@RestController
@EnableDynamicModuleAutoConfiguration(moduleJarAbsolutePath = "${ext.jars-path}")
@SpringBootApplication
public class ModuleApp {
    public static void main(String[] args) {
        SpringApplication.run(ModuleApp.class, args);
    }


    @Autowired
    private ModuleService services;

    @PostMapping("call/{module}/{version}")
    public void load(@PathVariable String module,
                     @PathVariable String version
    ) throws FileNotFoundException {
        services.handle(module, version, null);
    }
}
